package com.c2c.service.impl;

import com.c2c.mapper.AdminMapper;
import com.c2c.mapper.UserMapper;
import com.c2c.po.Admin;
import com.c2c.po.User;
import com.c2c.po.enums.impl.UsersState;
import com.c2c.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    AdminMapper adminMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> findAllUser() {
        return userMapper.findAllUser();
    }

    @Override
    public User findByUserAccount(int userAccount) {
        return userMapper.findByUserId(userAccount);
    }

    @Override
    public void updateUserByUserAccount(User user) {
        userMapper.updateInformationByUserId(user);
    }

    @Override
    public void updateUserStateByUserAccount(int userState, int userAccount) {
        for (UsersState usersState : UsersState.values()) {
            if (usersState.getCode() == userAccount) {
                userMapper.updateStateByUserId(userAccount, usersState);
            }
        }
    }

    @Override
    public void updateUserMoneyByUserAccount(User user) {
        userMapper.updateMoneyByUserId(user, true);
    }

    @Override
    public void insertUser(User user) {
        userMapper.insertUser(user);
    }

    @Override
    public Admin findByAdminId(String adminId) {
        return adminMapper.findById(adminId);
    }

    @Override
    public void updateAdminByAdminId(Admin admin) {
        adminMapper.updateById(admin);
    }
}
